package bug.persistent;

import bug.dao.api.IBaseDao;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlTransient;
import java.util.List;

/**
 * User: ion
 * Date: Aug 30, 2008 - 10:24:15 PM
 */

@Entity
public class User extends PO {
    
    private String loginName;
    private String firstName;
    private String lastName;
    private String email;
    private List<UserProject> userProjects;
    private List<Issue> issues;

    @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
    @Fetch(value = FetchMode.SUBSELECT)
    @XmlTransient
    public List<UserProject> getUserProjects() {
        return userProjects;
    }

    public void setUserProjects(List<UserProject> userProjects) {
        this.userProjects = userProjects;
    }

    @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
    @Fetch(value = FetchMode.SUBSELECT)
    @Cascade(value = {CascadeType.SAVE_UPDATE, CascadeType.LOCK, CascadeType.EVICT, CascadeType.MERGE})
    public List<Issue> getIssues() {
        return issues;
    }

    public void addIssue(Issue issue) {
        issue.setUser(this);
        this.getIssues().add(issue);
    }

    public void setIssues(List<Issue> issues) {
        this.issues = issues;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

}